# -*- bazel -*-

load("@drake//tools/skylark:cc.bzl", "cc_library")

package(default_visibility = ["//visibility:public"])

# TODO(calderpg-tri) This file is from the OpenCL C++ bindings, and is
# "Copyright (c) 2008-2015 The Khronos Group Inc." with a notice requirement in
# the license. Once voxelized_geometry_tools is used in production code, we
# will need to install that notice.
cc_library(
    name = "cl_hpp",
    hdrs = ["include/voxelized_geometry_tools/cl.hpp"],
    includes = ["include"],
    linkstatic = True,
    deps = ["@opencl"],
)

cc_library(
    name = "voxelized_geometry_tools",
    srcs = [
        "src/voxelized_geometry_tools/collision_map.cpp",
        "src/voxelized_geometry_tools/dynamic_spatial_hashed_collision_map.cpp",  # noqa
        "src/voxelized_geometry_tools/mesh_rasterizer.cpp",
        "src/voxelized_geometry_tools/signed_distance_field.cpp",
        "src/voxelized_geometry_tools/signed_distance_field_generation.cpp",  # noqa
        "src/voxelized_geometry_tools/tagged_object_collision_map.cpp",
    ],
    hdrs = [
        "include/voxelized_geometry_tools/collision_map.hpp",
        "include/voxelized_geometry_tools/dynamic_spatial_hashed_collision_map.hpp",  # noqa
        "include/voxelized_geometry_tools/mesh_rasterizer.hpp",
        "include/voxelized_geometry_tools/signed_distance_field.hpp",
        "include/voxelized_geometry_tools/signed_distance_field_generation.hpp",  # noqa
        "include/voxelized_geometry_tools/tagged_object_collision_map.hpp",
        "include/voxelized_geometry_tools/topology_computation.hpp",
        "include/voxelized_geometry_tools/vgt_namespace.hpp",
    ],
    includes = ["include"],
    linkstatic = True,
    deps = [
        "@common_robotics_utilities",
        "@eigen",
        "@zlib",
    ],
)

cc_library(
    name = "cuda_voxelization_helpers",
    srcs = [
        "src/voxelized_geometry_tools/dummy_cuda_voxelization_helpers.cc",
    ],
    hdrs = [
        "include/voxelized_geometry_tools/cuda_voxelization_helpers.h",
        "include/voxelized_geometry_tools/device_voxelization_interface.hpp",
        "include/voxelized_geometry_tools/vgt_namespace.hpp",
    ],
    includes = ["include"],
    linkstatic = True,
    deps = [
        "@common_robotics_utilities",
        "@eigen",
    ],
)

cc_library(
    name = "opencl_voxelization_helpers",
    srcs = [
        "src/voxelized_geometry_tools/opencl_voxelization_helpers.cc",
    ],
    hdrs = [
        "include/voxelized_geometry_tools/device_voxelization_interface.hpp",
        "include/voxelized_geometry_tools/opencl_voxelization_helpers.h",
        "include/voxelized_geometry_tools/vgt_namespace.hpp",
    ],
    includes = ["include"],
    linkstatic = True,
    deps = [
        ":cl_hpp",
        "@common_robotics_utilities",
        "@eigen",
    ],
)

cc_library(
    name = "pointcloud_voxelization",
    srcs = [
        "src/voxelized_geometry_tools/cpu_pointcloud_voxelization.cpp",
        "src/voxelized_geometry_tools/device_pointcloud_voxelization.cpp",
        "src/voxelized_geometry_tools/pointcloud_voxelization.cpp",
    ],
    hdrs = [
        "include/voxelized_geometry_tools/cpu_pointcloud_voxelization.hpp",
        "include/voxelized_geometry_tools/cuda_voxelization_helpers.h",
        "include/voxelized_geometry_tools/device_pointcloud_voxelization.hpp",
        "include/voxelized_geometry_tools/device_voxelization_interface.hpp",
        "include/voxelized_geometry_tools/opencl_voxelization_helpers.h",
        "include/voxelized_geometry_tools/pointcloud_voxelization.hpp",
        "include/voxelized_geometry_tools/pointcloud_voxelization_interface.hpp",  # noqa
    ],
    includes = ["include"],
    linkstatic = True,
    deps = [
        ":voxelized_geometry_tools",
        ":cuda_voxelization_helpers",
        ":opencl_voxelization_helpers",
        "@common_robotics_utilities",
        "@eigen",
        "@zlib",
    ],
)

# N.B. This test uses two threads even when OpenMP is not available.
cc_test(
    name = "pointcloud_voxelization_test",
    srcs = ["test/pointcloud_voxelization_test.cpp"],
    env = {"OMP_NUM_THREADS": "2"},
    tags = [
        "cpu:2",
        "no_kcov",
    ],
    deps = [
        ":voxelized_geometry_tools",
        ":cuda_voxelization_helpers",
        ":opencl_voxelization_helpers",
        ":pointcloud_voxelization",
        "@common_robotics_utilities",
        "@gtest//:without_main",
    ],
)

# N.B. This test uses two threads even when OpenMP is not available.
cc_test(
    name = "mesh_rasterization_test",
    srcs = ["test/mesh_rasterization_test.cpp"],
    env = {"OMP_NUM_THREADS": "2"},
    tags = [
        "cpu:2",
        "no_kcov",
    ],
    deps = [
        ":voxelized_geometry_tools",
        "@common_robotics_utilities",
        "@gtest//:without_main",
    ],
)

# N.B. This test uses two threads even when OpenMP is not available.
cc_test(
    name = "sdf_generation_test",
    srcs = ["test/sdf_generation_test.cpp"],
    env = {"OMP_NUM_THREADS": "2"},
    tags = [
        "cpu:2",
        "no_kcov",
    ],
    deps = [
        ":voxelized_geometry_tools",
        "@common_robotics_utilities",
        "@gtest//:without_main",
    ],
)

test_suite(
    name = "test_suite",
    tests = [
        ":mesh_rasterization_test",
        ":pointcloud_voxelization_test",
        ":sdf_generation_test",
    ],
)
